﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XPMVC.Controllers;

namespace XPMVC
{
    public partial class Login : System.Web.UI.Page
    {
        private AuthController auCtrl;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                auCtrl = new AuthController();

                var member = auCtrl.CheckLogin(loginUser.Text, loginPassword.Text);

                if (member != null)
                {
                    Session["username"] = member.username;
                    Session["id"] = member.id;

                    Response.Redirect("Default.aspx");
                }
                else
                {
                    loginError.InnerText = "Username and password combination not found";
                    loginError.Visible = true;
                }
            }
        }
    }
}